package flowSum;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author caoxiaofeng
 * @date 2021-07-14 23:36
 */
public class FlowCountDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //设置文件参数
        args = new String[]{"e:/input/inputflow","e:/output2"};
        Configuration conf = new Configuration();
        // 1. 获取job对象
        Job job = Job.getInstance(conf);

        //2. 设置jar的路径
        job.setJarByClass(FlowCountDriver.class);

        //3. 关联mapper 和 reducer
          job.setMapperClass(FlowCountMapper.class);
          job.setReducerClass(FlowCountReduce.class);
        //4. 设置mapper输出的key和value值
         job.setMapOutputKeyClass(Text.class);
         job.setMapOutputValueClass(FlowBean.class);
        //5. 设置最终输出的key和value值
          job.setOutputKeyClass(Text.class);
          job.setOutputValueClass(FlowBean.class);
        //6. 设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
        //7. 提交job
        boolean res = job.waitForCompletion(true);

        System.exit(res?0:1);
    }
}
